﻿using System;
using System.Collections.Generic;
using System.Text;


namespace IM.Model
{
    /// <summary>
    /// 即时消息
    /// </summary>
    public class InstantMessage
    {
        /// <summary>
        /// 过期时间(秒)
        /// </summary>
        public static int Timeout = 300;
        /// <summary>
        /// 信息
        /// </summary>
        public string Content { get; set; }

        /// <summary>
        /// 消息类型
        /// </summary>
        public InstantMessageType MessageType { get; set; }

        public int SenderId { get; set; }

        public int ReceiverId { get; set; }

        public DateTime SendTime { get; set; }

        private bool _isNew = true;
        /// <summary>
        /// 是否为新消息
        /// </summary>
        public bool IsNew
        {
            get { return _isNew; }
            set { _isNew = value; }
        }

        /// <summary>
        /// 消息是否过期，如果过期则说明接收者已经离线。
        /// </summary>
        public bool IsTimeout
        {
            get
            {
                return (DateTime.Now - SendTime.AddSeconds(Timeout)).Ticks > 0;
            }
        }
    }

    public enum InstantMessageType
    {
        /// <summary>
        /// 普通个人消息
        /// </summary>
        PersonalMessage = 2,
        /// <summary>
        /// 群消息
        /// </summary>
        GroupMessage = 3,
        /// <summary>
        /// 系统消息
        /// </summary>
        SystemMessage = 4
    }
}
